package com.cloudeasy.user.client;

import com.cloudeasy.api.enums.ResultCodeEnum;
import com.cloudeasy.api.util.ResultUtil;
import com.cloudeasy.api.vo.Result;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@CrossOrigin
@FeignClient(value = "cloudeasy-area", fallback = AreaClient.AreaClientFallback.class)
public interface AreaClient {

    /**
     * 判断父区域列表是否可以包含所有子区域列表
     *
     * @param parentNames 父区域列表
     * @param childNames  子区域列表
     * @return {@link Result<Boolean>}
     */
    @GetMapping("/is_sub_area")
    Result<Boolean> isSubArea(@RequestParam("parentNames") List<String> parentNames,
                                     @RequestParam("childNames") List<String> childNames);

    @Component
    static class AreaClientFallback implements AreaClient {
        @Override
        public Result<Boolean> isSubArea(List<String> parentNames, List<String> childNames) {
            return ResultUtil.failure(ResultCodeEnum.REMOTE_ERROR);
        }
    }
}
